package IC.Analyzer.Types;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

@SuppressWarnings("all")
public class ArrayType extends RefType {
	private Type elmType;

	private static Map<Type, ArrayType> cache = null;

	/**
	 * @param elmType
	 * @return a new array type or old if this already exists
	 */
	public static ArrayType getIt(Type elmType) {
		if (cache == null)
			cache = new HashMap<Type, ArrayType>();

		// first search in the cache
		ArrayType ret = cache.get(elmType);
		if (ret == null) {
			ret = new ArrayType(elmType);
			cache.put(elmType, ret);
		}
		return ret;
	}

	private ArrayType(Type elmType) {
		this.elmType = elmType;
	}

	public Type getElmType() {
		return elmType;
	}

	public String toString() {
		return elmType + "[]";
	}

	/**
	 * 
	 * @return a string represantation of all method types
	 */
	public static String toStringAll() {
		StringBuffer s = new StringBuffer();

		Set<Entry<Type, ArrayType>> set = cache.entrySet();

		for (Entry<Type, ArrayType> e : set) {
			s.append(e.getValue());
			s.append("\n");
		}

		return s.toString();
	}
}
